﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

using Vitruvian.Serialization;
using Vitruvian.Serialization.Formatters;
using Vitruvian.Windows.Serialization.Formatters;
using Vitruvian.Logging;
using Vitruvian.Testing;

namespace SpotItComponents
{
    [ContainsTests("Components.DeckStuff")]
    [OptimisticSerialization]
    public class SymbolPositioning : Component
    {
        #region Private Data Members
        private static Logger logger = Logger.GetLogger(typeof(SymbolPositioning));
        private static Dictionary<string, List<SymbolPositioning>> templates = null;
        #endregion

        #region Constructor(s)
        public SymbolPositioning() { }
        public SymbolPositioning(int x, int y, int radius)
        {
            CenterLocation = new Point(x, y);
            Radius = radius;
        }
        #endregion

        #region Public Properties and Methods
        public Point CenterLocation { get; set; }
        public int Radius { get; set; }
        public float Rotation { get; set; }
        public Symbol Symbol { get; set; }

        public static List<SymbolPositioning> Template(int numberOfSymbols)
        {
            List<SymbolPositioning> result = null;

            if (templates == null)
                SetupTemplates();
            if (templates.ContainsKey(numberOfSymbols.ToString()))
                result = templates[numberOfSymbols.ToString()];

            return result;
        }

        #endregion

        #region Private methods

        private static void SetupTemplates()
        {
            templates = new Dictionary<string, List<SymbolPositioning>>(10);


            // 3-card template
            List<SymbolPositioning> template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(210, 100, 80));
            template.Add(new SymbolPositioning(135, 280, 80));
            template.Add(new SymbolPositioning(310, 240, 56));
            templates.Add("3", template);

            // 4-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(175, 105, 80));
            template.Add(new SymbolPositioning(305, 160, 80));
            template.Add(new SymbolPositioning(250, 310, 116));
            template.Add(new SymbolPositioning(95, 240, 60));
            templates.Add("4", template);

            // 5-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(100, 125, 60));
            template.Add(new SymbolPositioning(255, 125, 90));
            template.Add(new SymbolPositioning(325, 255, 52));
            template.Add(new SymbolPositioning(195, 295, 75));
            template.Add(new SymbolPositioning(70, 235, 45));
            templates.Add("5", template);

            // 6-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(105, 130, 60));
            template.Add(new SymbolPositioning(195, 60, 45));
            template.Add(new SymbolPositioning(295, 150, 75));
            template.Add(new SymbolPositioning(320, 295, 55));
            template.Add(new SymbolPositioning(200, 300, 85));
            template.Add(new SymbolPositioning(70, 235, 45));
            templates.Add("6", template);

            // 7-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(100, 125, 60));
            template.Add(new SymbolPositioning(200, 60, 45));
            template.Add(new SymbolPositioning(295, 150, 75));
            template.Add(new SymbolPositioning(320, 295, 55));
            template.Add(new SymbolPositioning(200, 300, 80));
            template.Add(new SymbolPositioning(70, 235, 45));
            template.Add(new SymbolPositioning(180, 310, 90));
            templates.Add("7", template);

            // 8-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(100, 115, 60));
            template.Add(new SymbolPositioning(200, 60, 45));
            template.Add(new SymbolPositioning(295, 115, 75));
            template.Add(new SymbolPositioning(320, 265, 45));
            template.Add(new SymbolPositioning(245, 260, 35));
            template.Add(new SymbolPositioning(170, 325, 55));
            template.Add(new SymbolPositioning(75, 235, 45));
            template.Add(new SymbolPositioning(170, 205, 45));
            templates.Add("8", template);

            // 9-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(100, 115, 60));
            template.Add(new SymbolPositioning(200, 60, 45));
            template.Add(new SymbolPositioning(295, 115, 75));
            template.Add(new SymbolPositioning(320, 265, 45));
            template.Add(new SymbolPositioning(245, 260, 35));
            template.Add(new SymbolPositioning(155, 320, 55));
            template.Add(new SymbolPositioning(260, 340, 35));
            template.Add(new SymbolPositioning(75, 235, 45));
            template.Add(new SymbolPositioning(170, 205, 45));
            templates.Add("9", template);

            // 10-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(100, 115, 60));
            template.Add(new SymbolPositioning(200, 60, 45));
            template.Add(new SymbolPositioning(250, 170, 55));
            template.Add(new SymbolPositioning(355, 195, 30));
            template.Add(new SymbolPositioning(320, 265, 45));
            template.Add(new SymbolPositioning(245, 260, 35));
            template.Add(new SymbolPositioning(155, 320, 55));
            template.Add(new SymbolPositioning(260, 340, 35));
            template.Add(new SymbolPositioning(75, 235, 45));
            template.Add(new SymbolPositioning(170, 205, 45));
            templates.Add("10", template);

            // 11-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(100, 115, 60));
            template.Add(new SymbolPositioning(200, 60, 45));
            template.Add(new SymbolPositioning(290, 90, 35));
            template.Add(new SymbolPositioning(270, 175, 45));
            template.Add(new SymbolPositioning(355, 195, 30));
            template.Add(new SymbolPositioning(320, 265, 45));
            template.Add(new SymbolPositioning(245, 260, 35));
            template.Add(new SymbolPositioning(155, 320, 55));
            template.Add(new SymbolPositioning(260, 340, 35));
            template.Add(new SymbolPositioning(75, 235, 45));
            template.Add(new SymbolPositioning(170, 205, 45));
            templates.Add("11", template);

            // 12-card template
            template = new List<SymbolPositioning>();
            template.Add(new SymbolPositioning(100, 115, 60));
            template.Add(new SymbolPositioning(200, 60, 45));
            template.Add(new SymbolPositioning(290, 90, 35));
            template.Add(new SymbolPositioning(270, 175, 45));
            template.Add(new SymbolPositioning(355, 195, 30));
            template.Add(new SymbolPositioning(320, 265, 45));
            template.Add(new SymbolPositioning(245, 260, 35));
            template.Add(new SymbolPositioning(155, 320, 55));
            template.Add(new SymbolPositioning(260, 340, 35));
            template.Add(new SymbolPositioning(75, 235, 45));
            template.Add(new SymbolPositioning(170, 205, 45));
            template.Add(new SymbolPositioning(205, 135, 25));
            templates.Add("12", template);

        }
        #endregion
    }
}
